//
//  ApiUrl.m
//  Oos4ios
//
//  Created by Pablo Gonzalez on 3/16/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import "ApiUrl.h"


@implementation ApiUrl

@synthesize url = mUrl;

- (NSString *) description
{
	return (mUrl) ? mUrl : [super description];
}

- (NSString *) getUrl:(NSString *)firstItem, ...
{	
	NSString *result = [[mUrl copy] autorelease];
	if (firstItem) {
		va_list arguments;
		va_start(arguments, firstItem);
		NSString *argument = firstItem;
		do {
			result = [result stringByAppendingFormat: @"/%@", argument];
		} while ((argument = va_arg(arguments, NSString *)));
		va_end(arguments);
	}
	return result;
}

+ (ApiUrl *) apiUrl
{
	return [[ApiUrl new] autorelease];
}

- (void) setUrl: (NSString *) url
{
	mUrl = [url retain];
}

- (ApiUrl *) urlByAppendingSlug:(NSString *)slug
{
	ApiUrl *result = [[[ApiUrl alloc] init] autorelease];
	result->mUrl = [[mUrl stringByAppendingString:slug] retain];
	return result;
}

- (NSString *) absolutePath
{
	return mUrl;
}

- (void) dealloc
{
	[mUrl release];
	[super dealloc];
}

@end
